package com.jiukuaidao.zhulin.module.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jiukuaidao.library.base.BaseActivity;
import com.jiukuaidao.library.base.BaseXrecyclerViewAdapter;
import com.jiukuaidao.library.util.ToastUtil;
import com.jiukuaidao.library.widget.recyclerview.XRecyclerView;
import com.jiukuaidao.zhulin.R;
import com.jiukuaidao.zhulin.adapter.OrderListAdapter;
import com.jiukuaidao.zhulin.data.TaskProvider;
import com.jiukuaidao.zhulin.entity.ApiOrderList;
import com.jiukuaidao.zhulin.module.order.contract.OrderListContract;
import com.jiukuaidao.zhulin.module.order.presenter.OrderListPresenter;

import java.util.List;

import butterknife.BindView;

/**
 * Author : PaiTaSuo
 * Date : 2016/6/7
 * Description : 退款
 */
public class RefundActivity extends BaseActivity<OrderListContract.Presenter> implements OrderListContract.View, View.OnClickListener {
    @BindView(R.id.titile_text)
    TextView mTitleText;
    @BindView(R.id.titile_left_imageview)
    ImageView mLeftImg;
    @BindView(R.id.order_recycle)
    XRecyclerView mOrderRecycle;
    private String mStatus;
    private int mIndex = 1;
    private BaseXrecyclerViewAdapter mBaseAdapter;
    private int mRefreshOrLoad = OrderListContract.REFRESH;

    @Override
    protected View getTargetView() {
        return null;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_refund;
    }

    @Override
    protected void handleBundle(Bundle bundle) {
        mStatus = String.valueOf(bundle.getInt("type"));
    }

    @Override
    protected void init() {
        mTitleText.setText("退款");
        new OrderListPresenter(TaskProvider.provideOrderListRepository(this), this);
        mPresenter.start();
        setOnClickListenter();
    }

    @Override
    public int getIndex() {
        return mIndex;
    }

    @Override
    public String getStatus() {
        return mStatus;
    }

    @Override
    public void orderList(List<ApiOrderList.OrderList> orderList) {
        if (null != mBaseAdapter) {
            mBaseAdapter.setData(orderList);
            mBaseAdapter.notifyDataSetChanged();
        } else {
            initOrderList(orderList);
        }
    }

    public void initOrderList(List<ApiOrderList.OrderList> list) {
        mBaseAdapter = new OrderListAdapter(this, R.layout.item_order_list, list, mOrderRecycle);
        mOrderRecycle.setLayoutManager(new LinearLayoutManager(this));
        mOrderRecycle.setAdapter(mBaseAdapter);
        mOrderRecycle.setOnRefreshListener(new XRecyclerView.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mOrderRecycle.refreshComplete();
            }

            @Override
            public void onLoadMore() {
                mOrderRecycle.loadMoreComplete();
            }
        });
    }


    @Override
    public void toast(String msg) {
        ToastUtil.show(msg, Toast.LENGTH_SHORT);
    }

    @Override
    public int refreshOrLoad() {
        return mRefreshOrLoad;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titile_left_imageview:
                finish();
                break;
        }
    }

    public void setOnClickListenter() {
        mLeftImg.setOnClickListener(this);
    }
}
